package dao;

import hbt.HibernateUtil;
import negocio.Comanda;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class ComandaDAO {

	private static ComandaDAO instancia = null;
	private static SessionFactory sf = null;
	
	public ComandaDAO()
	{
		
	}
	public static ComandaDAO getInstancia()
	{
		if (instancia== null)
		{			
			sf = HibernateUtil.getSessionFactory();
			instancia = new ComandaDAO();
		}
		return instancia;
	}

	public void grabarComanda(Comanda c)
	{
		Session s = sf.openSession();
		s.beginTransaction();
		s.persist(c);
		s.flush();
		s.getTransaction().commit();
		s.close();
	}

	public Comanda buscarComanda(int nroComanda) {
		Session session = sf.openSession();
		Comanda c = new Comanda();
		c.setNroComanda(nroComanda); 
		session.load(c, c.getNroComanda());			
		session.close();
		return c;
	}
	
}

